﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AiKiDo2
{
    public partial class InputDataForm : Form
    {
        #region Fields

        private double m_x0 = 1;
        private double m_y0 = 1;
        private double m_z0 = 1;

        private double step = 1e-1;
        private int maxStepCount = int.MaxValue;

        #endregion

        public InputDataForm()
        {
            InitializeComponent();

            X0 = Y0 = Z0 = 1;
        }

        public double X0
        {
            get
            {
                return m_x0;
            }
            set
            {
                m_x0 = value;

                x0TextBox.Text = m_x0.ToString();
            }
        }

        public double Y0
        {
            get
            {
                return m_y0;
            }
            set
            {
                m_y0 = value;

                y0TextBox.Text = m_y0.ToString();
            }
        }

        public double Z0
        {
            get
            {
                return m_z0;
            }
            set
            {
                m_z0 = value;

                z0TextBox.Text = m_z0.ToString();
            }
        }

        public double R
        {
            get
            {
                return rTrackBar.Value;
            }
            set
            {
                if( value >= 0 && value < 30 )
                    rTrackBar.Value = ( int )value;
            }
        }

        public int MaxStepCount
        {
            get
            {
                return maxStepCount;
            }
            set
            {
                maxStepCount = value;

                maxStepCountTextBox.Text = maxStepCount.ToString();
            }
        }

        public double Step
        {
            get
            {
                return step;
            }
            set
            {
                step = value;

                stepTextBox.Text = step.ToString();
            }
        }

        private void x0TextChanged( object sender, EventArgs e )
        {
            double res;
            if( !double.TryParse( x0TextBox.Text, out res ) )
            {
                x0TextBox.Text = m_x0.ToString();
                return;
            }

            m_x0 = res;
        }

        private void y0TextChanged( object sender, EventArgs e )
        {
            double res;
            if( !double.TryParse( y0TextBox.Text, out res ) )
            {
                y0TextBox.Text = m_y0.ToString();
                return;
            }

            m_y0 = res;
        }

        private void z0TextChanged( object sender, EventArgs e )
        {
            double res;
            if( !double.TryParse( z0TextBox.Text, out res ) )
            {
                z0TextBox.Text = m_z0.ToString();
                return;
            }

            m_z0 = res;
        }

        private void stepTextChanged( object sender, EventArgs e )
        {
            double res;
            if( !double.TryParse( stepTextBox.Text, out res ) )
            {
                stepTextBox.Text = step.ToString();
                return;
            }

            step = res;
        }

        private void maxStepCountTextChanged( object sender, EventArgs e )
        {
            int res;
            if( !int.TryParse( maxStepCountTextBox.Text, out res ) )
            {
                maxStepCountTextBox.Text = maxStepCount.ToString();
                return;
            }

            maxStepCount = res;
        }

        private void acceptButton_Click( object sender, EventArgs e )
        {
            DialogResult = DialogResult.OK;
        }

        private void rTrackBar_Scroll(object sender, EventArgs e)
        {
            label_RValue.Text = R.ToString();
        }
    }
}
